package com.kaigejava.kgseed.configurer;

import com.kaigejava.kgseed.interceptor.ErrorInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 拦截器配置
 * @author xwolf
 * @version 1.0
 * @since 1.8
 */
//@Configuration
@Slf4j
public class InterceptorConfig extends WebMvcConfigurerAdapter {

    /**
     * CSRF拦截
     * @return
     */
  @Bean
    CsrfInterceptor csrfInterceptor(){
        return new CsrfInterceptor();
    }
    /**
     * 错误拦截
     * @return
     */
    @Bean
    ErrorInterceptor errorInterceptor(){
        log.error("进入错误拦截器。。。。。");
        return new ErrorInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

       // registry.addInterceptor(csrfInterceptor()).addPathPatterns("/**").excludePathPatterns("userpage/config").excludePathPatterns("/config");
        registry.addInterceptor(csrfInterceptor()).addPathPatterns("/**").excludePathPatterns("/config").excludePathPatterns("/sys");
        registry.addInterceptor(errorInterceptor()).addPathPatterns("/**").excludePathPatterns("/config").excludePathPatterns("/sys");

        super.addInterceptors(registry);
    }
}
